#include <iostream>
#include <queue>
using namespace std;

#include "BitStack.h"
#include "BitQueue.h"
#include "Bit_PriorityQueue.h"


void test_stack()
{
	//bit::stack<int,vector<int>> s;  //数组栈
	//bit::stack<int, list<int>> s; //链表栈
	bit::stack<int> s;
	//bit::stack<int, deque<int>> s;

	s.push(1);
	s.push(2);
	s.push(3);
	s.push(4);
	while (!s.empty())
	{
		cout << s.top() << " ";
		s.pop();
	}
	cout << endl;
}


void test_queue()
{
	//bit::queue<int, vector<int>> q;
	bit::queue<int> q;

	q.push(1);
	q.push(2);
	q.push(3);
	q.push(4);
	while (!q.empty())
	{
		cout << q.front() << " ";
		q.pop();
	}
	cout << endl;
}


void test_priority_queue()
{
	//vector<int> v = { 3,2,7,6,0,4,1,9,8,5 };
	///*priority_queue<int> q1;
	//for (auto& e : v)
	//	q1.push(e);*/

	//priority_queue<int> q1(v.begin(), v.end());

	int a[] = { 3,2,7,6,0,4,1,9,8,5 };
	// 默认是大堆
	//bit::priority_queue<int> q1(a, a+sizeof(a)/sizeof(int));
	// 小堆
	bit::priority_queue<int, vector<int>, bit::mygreater<int>> q1(a, a + sizeof(a) / sizeof(int));

	while (!q1.empty())
	{
		cout << q1.top() << " ";
		q1.pop();
	}
	cout << endl;
}



// 仿函数/函数对象：重载了oparator（）的类，类的对象可以像函数一样使用
// operator()特点，参数个数和返回值根据需求确定，不固定，很多样化
class Func
{
public:
	//void operator()() //()函数调用参数列表括号运算
	//{
	//	cout << "Func调用" << endl;
	//}
	void operator()(int n = 1) //()函数调用参数列表括号运算
	{
		while (n--)
		{
			cout << "Func调用" << endl;
		}
	}
};



template<class T>
class myless
{
public:
	bool operator()(const T& x, const T& y)
	{
		return x < y;
	}
};

class Date
{
public:
	Date(int year = 1900, int month = 1, int day = 1)
		: _year(year)
		, _month(month)
		, _day(day)
	{}
	bool operator<(const Date& d)const
	{
		return (_year < d._year) ||
			(_year == d._year && _month < d._month) ||
			(_year == d._year && _month == d._month && _day < d._day);
	}
	bool operator>(const Date& d)const
	{
		return (_year > d._year) ||
			(_year == d._year && _month > d._month) ||
			(_year == d._year && _month == d._month && _day > d._day);
	}

	friend ostream& operator<<(ostream& _cout, const Date& d);

private:
	int _year;
	int _month;
	int _day;
};


ostream& operator<<(ostream& _cout, const Date& d)
{
	_cout << d._year << "-" << d._month << "-" << d._day;
	return _cout;
}

//没有这个的话，下面日期输出有问题，但是当我们在头文件里写了偏特化就不会
//struct PDateLess
//{
//	bool operator()(Date* p1, Date* p2)
//	{
//		return *p1 < *p2;
//	}
//};

void TestPriorityQueue()
{
	// 大堆，需要用户在自定义类型中提供<的重载
	bit::priority_queue<Date*> q1;
	//bit::priority_queue<Date*,vector<Date*>,PDateLess> q1;
	q1.push(new Date(2018, 10, 29));
	q1.push(new Date(2018, 10, 28));
	q1.push(new Date(2018, 10, 30));

	while (!q1.empty())
	{
		cout << *q1.top() << " ";
		q1.pop();
	}

	cout << "\n";

	bit::priority_queue<int*> q2;
	q2.push(new int(1));
	q2.push(new int(2));
	q2.push(new int(3));

	while (!q2.empty())
	{
		cout << *q2.top() << " ";
		q2.pop();
	}



}



int main()
{
	//test_stack();
	//test_queue();
	test_priority_queue();

	//Func f1;
	//f1(10);
	//f1.operator()();

	/*myless<int> lessFunc1;
	cout << lessFunc1(1, 2) << endl;*/
	//// lessFunc1.operator()(1,2) 底层转换

	//myless<string> lessFunc2;
	//cout << lessFunc2("1111", "2222") << endl;

	TestPriorityQueue();

	return 0;
}